Skip to content

Add render_graph for spatial connectivity visualization#592

Merged
timtreis merged 1 commit into
mainfrom
feature/render-graph
May 11, 2026
Merged

Add render_graph for spatial connectivity visualization#592
timtreis merged 1 commit into
mainfrom
feature/render-graph

Conversation

@timtreis
Copy link
Copy Markdown
Member

@timtreis timtreis commented Apr 16, 2026

Summary

  • Adds sdata.pl.render_graph() to render spatial graph edges from adjacency matrices stored in table.obsp, using element centroids for coordinates via spatialdata.get_centroids()
  • Supports shapes, points, and labels elements
  • Includes groups + group_key filtering (both-endpoints semantics) and auto-discovery of element/table when unambiguous

API

# Basic: edges over shapes
sdata.pl.render_graph("cells", connectivity_key="spatial").pl.render_shapes("cells").pl.show()

# Full composition: image + graph + labels
sdata.pl.render_images("he").pl.render_graph("seg", table_name="table").pl.render_labels("seg").pl.show()

# Filtered: only tumor-to-tumor edges
sdata.pl.render_graph("cells", group_key="cell_type", groups=["tumor"]).pl.render_shapes("cells", color="cell_type").pl.show()

Implementation details

  • connectivity_key accepts full obsp key or prefix (auto-resolves "spatial""spatial_connectivities")
  • No networkx dependency — direct sparse matrix upper triangle → LineCollection
  • Rasterized by default for performance

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 80.25890% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.47%. Comparing base (84e5da7) to head (35ee4ce).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/utils.py 70.50% 22 Missing and 19 partials ⚠️
src/spatialdata_plot/pl/render.py 86.46% 7 Missing and 11 partials ⚠️
src/spatialdata_plot/pl/basic.py 85.71% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #592      +/-   ##
==========================================
+ Coverage   77.07%   77.47%   +0.39%     
==========================================
  Files          11       11              
  Lines        3280     3569     +289     
  Branches      774      837      +63     
==========================================
+ Hits         2528     2765     +237     
- Misses        454      481      +27     
- Partials      298      323      +25     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/render_params.py 88.10% <100.00%> (+1.34%) ⬆️
src/spatialdata_plot/pl/basic.py 86.60% <85.71%> (+0.22%) ⬆️
src/spatialdata_plot/pl/render.py 87.31% <86.46%> (+0.13%) ⬆️
src/spatialdata_plot/pl/utils.py 67.56% <70.50%> (+0.23%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis timtreis force-pushed the feature/render-graph branch 11 times, most recently from 33e1d4c to 96b07df Compare May 11, 2026 20:44
Adds sdata.pl.render_graph() to draw spatial graph edges from
adjacency matrices stored in table.obsp, using element centroids
as node positions. Supports shapes, points, and labels. Features:

- Scalar / obs-categorical / obs-continuous / obsp-matrix edge coloring
- Per-edge widths and alphas (scalar or from a weight matrix)
- Group filtering (both endpoints must be in the requested groups)
- Self-loop rendering as a CircleCollection
- Integrated colorbar via the existing ColorbarSpec pipeline
- Legend sharing with chained render_shapes / render_points
- No new dependencies (no networkx)
@timtreis timtreis force-pushed the feature/render-graph branch from 96b07df to 35ee4ce Compare May 11, 2026 20:50
@timtreis timtreis merged commit 53abe71 into main May 11, 2026
7 of 8 checks passed
@timtreis timtreis deleted the feature/render-graph branch May 11, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants